<?php //Pagina principala a site-ului
require_once("/includes/config.php");
$page_title = "Fifaonline.ro | Campionate fifa virtuale | Stiri sportive";
include_once("/includes/head.php");
?>
<body>
<?php
include_once("/includes/header.php");
?>
<!--body start -->
<div id="body">
<!--left panel start -->
<?php
include_once("/includes/sidea.php");
?>
<!--left panel end -->
<!--right panel start -->
<div id="right">
<?php
if(!isset($_SESSION["first_name"]))
{
	$url = 'http://' . $_SERVER['HTTP_HOST'] . dirname ($_SERVER['PHP_SELF']);
	if((substr($url, -1) == '/') OR (substr($url, -1) == '\\'))
	{
		$url = substr($url, 0, -1);
	}
	$url .= '/index.php';
	ob_end_clean();
	header("Location:$url");
	exit();
}
else
{
	if(isset($_POST["submitted"]))
	{
		require_once("/includes/mysql_connect.php");
		if(eregi('^[[:alnum:]]{4,20}$', stripslashes(trim($_POST["password"]))))
		{
			if($_POST["password1"] == $_POST["password2"])
			{
				$password = escape_data($_POST["password1"]);
			}
			else
			{
				$password = FALSE;
				echo "<p><font color='red'>Parola ta nu se potriveste cu cea confirmata</font></p>";
			}
			}
			else
			{
				$password = FALSE;
				echo "<p><font color='red'>Tasteaza o parola valida</font></p>";
			}
			
			if($password)
			{
				$query = "UPDATE users SET pasword = SHA('$password') WHERE user_id={$_SESSION['user_id']}";
				$result = mysql_query($query) or trigger_error("Query: $query\n<br> MySQL Error: " . mysql_error());
				if(mysql_affected_rows() == 1)
				{
					echo "<h3>Parola ta a fost schimbata</h3>";
					mysql_close();
					exit();
				}
				else
				{
					echo "<p><font color='red'>Parola ta nu a putut fi schimbata datorita unei erori de sistem.</font></p>";
				}
			}
			else
			{
				echo "<p><font color='red'>Mai incearca o data</font>";
			}
			mysql_close();
		}
		?>
        <form action="change_password.php" method="post">
        <fieldset>
        <table><tr>
        <td><p class="text2">Parola noua: </p></td><td><input type="text" name="password1"><small>Foloseste doar litere si numere. (4-20 caractere)</small></td></tr>
        <tr><td><p class="text2">Confirma parola noua: </p></td><td><input type="text" name="password2"></td></tr></table>
        <input type="submit" name="submit" value="Schimba parola">
        <input type="hidden" value="TRUE" name="submitted">
        </fieldset>
        </form>
        <?php
		}
		?>
</div>
<!--right panel end -->
<br class="spacer" />
</div>
<!--body end -->
<!--footer start -->
<?php
include_once("/includes/footer.php");
?>
<!--footer end -->
</body>
</html>
